home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / lib / usleep.c < prev   
Encoding:
C/C++ Source or Header  |  1999-10-16  |  2.2 KB  |  101 lines

  1. /* @(#)usleep.c    1.14 99/10/16 Copyright 1995 J. Schilling */
  2. #ifndef lint
  3. static    char sccsid[] =
  4.     "@(#)usleep.c    1.14 99/10/16 Copyright 1995 J. Schilling";
  5. #endif
  6. /*
  7.  *    Copyright (c) 1995 J. Schilling
  8.  */
  9. /*
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2, or (at your option)
  13.  * any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; see the file COPYING.  If not, write to
  22.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include <mconfig.h>
  26. #include <standard.h>
  27. #include <stdxlib.h>
  28. #include <timedefs.h>
  29. #ifdef    HAVE_POLL_H
  30. #    include <poll.h>
  31. #else
  32. #    ifdef    HAVE_SYS_POLL_H
  33. #    include <sys/poll.h>
  34. #    endif
  35. #endif
  36. #ifdef    HAVE_SYS_SYSTEMINFO_H
  37. #include <sys/systeminfo.h>
  38. #endif
  39. #include <libport.h>
  40.  
  41. /*
  42.  * SCO has a usleep() prototype in unistd.h
  43.  * So we put this prototype before the #undef HAVE_USLEEP
  44.  */
  45. #ifndef    HAVE_USLEEP
  46. EXPORT    int    usleep        __PR((int usec));
  47. #endif
  48.  
  49. #ifdef    OPENSERVER
  50. /*
  51.  * Don't use the usleep() from libc on SCO's OPENSERVER.
  52.  * It will kill our processes with SIGALRM.
  53.  */
  54. #undef    HAVE_USLEEP
  55. #endif
  56.  
  57. #if    !defined(HAVE_USLEEP)
  58.  
  59. EXPORT int
  60. usleep(usec)
  61.     int    usec;
  62. {
  63. #if    defined(HAVE_SELECT)
  64. #define    HAVE_USLEEP
  65.  
  66.     struct timeval tv;
  67.     tv.tv_sec = usec / 1000000;
  68.     tv.tv_usec = usec % 1000000;
  69.     select(0, 0, 0, 0, &tv);
  70. #endif
  71.  
  72. #if    defined(HAVE_POLL) && !defined(HAVE_USLEEP)
  73. #define    HAVE_USLEEP
  74.  
  75.     if (poll(0, 0, usec/1000) < 0)
  76.         comerr("poll delay failed.\n");
  77.  
  78. #endif
  79.  
  80. #if    defined(HAVE_NANOSLEEP) && !defined(HAVE_USLEEP)
  81. #define    HAVE_USLEEP
  82.  
  83.     struct timespec ts;
  84.  
  85.     ts.tv_sec = usec / 1000000;
  86.     ts.tv_nsec = (usec % 1000000) * 1000;
  87.  
  88.     nanosleep(&ts, 0);
  89. #endif
  90.  
  91.  
  92. #if    !defined(HAVE_USLEEP)
  93. #define    HAVE_USLEEP
  94.  
  95.     sleep((usec+500000)/1000000);
  96. #endif
  97.  
  98.     return (0);
  99. }
  100. #endif
  101.